(function (a) {
  
    a.fn.timeCountDown = function (c) {
        var f = {
            start: null,
            end: new Date(Date.UTC(2050, 0, 1)),
            now: new Date().getTime(),
            mode: 1,
            cls: {
                day: "ct-day",
                hour: "ct-hour",
                min: "ct-min",
                sec: "ct-sec",
                dsec: "ct-dsec"
            },
            startHtml: "尚未开始",
            endHtml: "已结束",
            padding: true,
            useHtml: false
        };
        var h = a.extend({},
        f, c),
        e = {};
        var g = ['<span class="' + h.cls.day + '"></span>天', '<span class="' + h.cls.hour + '"></span>小时', '<span class="' + h.cls.min + '"></span>分', '<span class="' + h.cls.sec + '"></span>' + (h.mode == 3 ? '<span class="' + h.cls.dsec + '"></span>' : "") + "秒"];
        if (h.mode != 1) {
            g.splice(0, 1)
        }
        return this.each(function () {
            var m = a(this),
            o,
            n = Math.floor((h.end - h.now) / 1000);
            if (!h.useHtml) {
                m.html(g.join(" "))
            }
            for (var l in h.cls) {
                e[l] = m.find("." + h.cls[l]) || null
            }
            if (h.end && b(h.end, h.now) <= 0) {
                m.html(h.endHtml);
                return false
            } else {
                if (h.start && b(h.start, h.now) > 0) {
                    m.html(h.startHtml);
                    return false
                }
            }
            o = setInterval(function () {
                var r = i(n);
                for (var q in e) {
                    if (q != null) {
                        e[q].html(r[q])
                    }
                }
                if (h.end && n <= 0) {
                    m.html(h.endHtml);
                    if (h.onEnd && a.isFunction(h.onEnd)) {
                        h.onEnd.call(this)
                    }
                    if (o) {
                        clearTimeout(o)
                    }
                    if (k) {
                        clearTimeout(k)
                    }
                    return
                }
                n--
            },
            1000);
            if (h.mode == 3) {
                var j = 0,
                k = setInterval(function () {
                    j = (++j) % 10;
                    e.dsec.html("." + (9 - j))
                },
                100)
            }
        });
        function i(j) {
            pms = {
                sec: 0,
                min: 0,
                hour: 0,
                day: 0
            };
            if (j > 0) {
                pms.sec = d(j % 60);
                pms.min = Math.floor((j / 60)) > 0 ? d(Math.floor((j / 60)) % 60) : "0";
                pms.hour = Math.floor((j / 3600)) > 0 ? (h.mode == 2 || h.mode == 3) ? parseInt(Math.floor(j / 3600), 10) : d(Math.floor((j / 3600)) % 24) : "0";
                if (e.day) {
                    pms.day = Math.floor((j / 86400)) > 0 ? d(Math.floor((j / 86400))) : "0"
                }
            }
            return pms
        }
        function d(j) {
            var k = j;
            if (h.padding) {
                k = parseInt(j, 10);
                if (k > 0 && k <= 9) {
                    k = "0" + k
                } else {
                    if (k <= 0) {
                        k = "0"
                    }
                }
            }
            return k.toString()
        }
        function b(k, j) {
            if (!j) {
                j = new Date().getTime()
            }
            return (k - j)
        }
    };
  
})(jQuery);
